package com.laolei.core.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import com.laolei.core.Context;
import com.laolei.core.model.ResponseEntity;

@Controller
public class ExceptionController {

	@GetMapping("/exception/400")
	public ModelAndView notfound(HttpServletRequest request, HttpServletResponse response) {
		GlobalExceptionStatus status = GlobalExceptionStatus.PAGE_NOT_FOUND;
		return GlobalApiExceptionHandler.outException(request, response, ResponseEntity.now(status, Context.getRequestUri() + "请求失败"), status.getGoUrl());
	}

	@GetMapping("/exception/500")
	public ModelAndView serverError(HttpServletRequest request, HttpServletResponse response) {
		Exception ex = (Exception) request.getAttribute("javax.servlet.error.exception");
		return GlobalApiExceptionHandler.outException(request, response, ex);
	}
}
